﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.StopZero.CompositeConverter
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;


namespace DnProcessSimulateCommands.StopZero;

[ContentProperty("Converters")]
public class CompositeConverter : IValueConverter
{
  private readonly List<IValueConverter> _converters = new List<IValueConverter>();

  public List<IValueConverter> Converters => this._converters;

  public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  {
    if (value == DependencyProperty.UnsetValue)
      return value;
    foreach (IValueConverter converter in this.Converters)
    {
      value = converter.Convert(value, targetType, parameter, culture);
      if (value == Binding.DoNothing)
        return Binding.DoNothing;
    }
    return value;
  }

  public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  {
    if (value == DependencyProperty.UnsetValue)
      return value;
    foreach (IValueConverter valueConverter in this.Converters.Reverse<IValueConverter>())
    {
      value = valueConverter.Convert(value, targetType, parameter, culture);
      if (value == Binding.DoNothing)
        return Binding.DoNothing;
    }
    return value;
  }
}
